package com.woniu.order.controller;


import com.woniu.order.service.ICouponsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.woniu.entity.Result;
import com.woniu.order.pojo.Coupons;
import com.woniu.order.service.ICouponsService;
import com.woniu.user.pojo.Feedback;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@Api(tags = "优惠券管理")
@RestController
@RequestMapping("/coupons")
public class CouponsController {

    @Autowired
    private ICouponsService couponsService;



    @ApiOperation("新增或修改优惠券")
    @PostMapping("/saveOrUpdate")
    public Result<Coupons> querySave(@RequestBody Coupons coupons){
        boolean save = couponsService.saveOrUpdate(coupons);
        return Result.ok();
    }

    @ApiOperation("查询所有优惠券")
    @GetMapping("/findAll")
    public Result<List<Coupons>> queryAll(){
        List<Coupons> couponsList = couponsService.list();
        return Result.ok(couponsList);
    }

    @ApiOperation("删除优惠券")
    @DeleteMapping("/{id}")
    public Result queryDelete(@PathVariable Integer id){
        couponsService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("更改状态，是否可用")
    @PutMapping("/{id}")
    public Result queryStatus(@PathVariable Long id){

        boolean b = couponsService.queryCouponsType(id);

        return Result.ok();
    }

    @ApiOperation("查询发布优惠券数据")
    @GetMapping("/list")
    public Result<List<Coupons>> listSeckill(){
        List<Coupons> seckillList = couponsService.listSeckill();
        return Result.ok(seckillList);
    }

    @ApiOperation("根据id查询优惠券")
    @GetMapping("/{id})")
    public Result<Coupons> getById(@PathVariable Integer id){
        Coupons coupons = couponsService.getById(id);
        return Result.ok(coupons);
    }

    @ApiOperation("更改库存")
    @GetMapping("/updateCouponsById/{id})")
    public Result updateById(@PathVariable Integer id){
        boolean b = couponsService.updateCouponsById(id);
        return Result.ok();
    }

}
